function axios({
  url,
  method="GET",
  params={},
  data={}
}){
  return new Promise((resovle , reject)=>{
    // 处理method参数
    method = method.toUpperCase()

    // 处理query参数
    let queryStr = Object.keys(params).reduce((prev , current)=>{
      return `${prev}${current}=${params[current]}&`
    },'')
    if(queryStr){
      queryStr = queryStr.slice(0,-1)
      url += '?'+queryStr
    }

    // 执行异步ajax请求
    const xhr = new XMLHttpRequest()

    xhr.open(method, url)

    if(method === 'GET' || method === 'DELETE'){
      xhr.send()
    }else if(method === 'POST' || method ==='PUT'){
      xhr.setRequestHeader('Content-Type','application/json;charset=utf-8')
      xhr.send(JSON.stringify(data))
    }

    xhr.onreadystatechange= ()=>{
      if(xhr.readyState !==4){
        return
      }

      const { status , statusText } = xhr

      if(status>=200 && status<=299){
        const response ={
          data: JSON.parse(xhr.response),
          status,
          statusText
        }
        resovle(response) // 如果成功，调用resolve
      }else{
        reject(new Error('request error status is '+ status)) // 如果失败，调用reject
      }
    }  
  })
}
